package com.llmops.core;

import com.llmops.core.tracing.ExecutionTracer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CopyOnWriteArrayList;

public abstract class Node implements Worker{
    protected static final Logger logger = LoggerFactory.getLogger(Node.class);

    public enum NodeStatus { PENDING, RUNNING, SUCCESS, ERROR }

    protected String id;
    protected String title;
    protected Map<String, Object> config;
    protected List<Node> previousNodes = new CopyOnWriteArrayList<>();
    protected NodeStatus status = NodeStatus.PENDING;
    
    public void setStatus(NodeStatus status) {
        this.status = status;
    }
    
    public NodeStatus getStatus() {
        return this.status;
    }

    public Node(String id,String title, Map<String, Object> config) {
        this.id = id;
        this.title = title;
        this.config = config;
    }

    public abstract String getType();

    public Map<String, Object> getConfig() {
        return config;
    }

    protected void preExecute(Context context) {
        ExecutionTracer.logPreExecute(this, context);
    }

    protected void postExecute(Context context) {
        ExecutionTracer.logPostExecute(this, context);
    }

    public String getId() {
        return id;
    }

    public List<Node> getPreviousNodes() {
        return Collections.unmodifiableList(previousNodes);
    }

    public Node getPreviousNode() {
        return previousNodes.get(0);
    }
}